//
//  KAEQRCodeController.m
//  StudyDemo
//
//  Created by Kael on 2018/8/22.
//  Copyright © 2018年 陶涛. All rights reserved.
//

#import "KAEQRCodeController.h"
#import "UIImage+KAEQRCode.h"

@interface KAEQRCodeController ()

@property (nonatomic, strong) UIImageView *imageView;

@property (nonatomic, strong) UITextField *textField;


@end

@implementation KAEQRCodeController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
}

- (void)setUI {
    self.imageView = [[UIImageView alloc] init];
    self.imageView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.imageView];
   
    
    self.textField = [[UITextField alloc] init];
    self.textField.placeholder = @"输入字符串生成二维码";
    self.textField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:self.textField];
    
    
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:@"生成二维码" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor blueColor];
    [button addTarget:self action:@selector(createQRCode) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_topLayoutGuide).offset(20);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
    }];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.textField.mas_bottom).offset(30);
        make.centerX.equalTo(self.view);
    }];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(button.mas_bottom).offset(30);
        make.width.equalTo(self.imageView.mas_height);
        make.width.mas_equalTo(200);
    }];
    
}

- (void)createQRCode {
    self.imageView.image = [UIImage kae_createQRCodeImageUseString:self.textField.text imageSize:300];
}


@end



























